package com.edu.backend.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.edu.backend.dao.ExamLabelDao;
import com.edu.backend.entity.ExamLabel;
import com.edu.backend.entity.PagerInfo;
import com.edu.backend.service.ExamLabelService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ExamLabelServiceImpl extends ServiceImpl<ExamLabelDao, ExamLabel> implements ExamLabelService {
    @Override
    public PagerInfo<ExamLabel> getExamLabelList(PagerInfo<ExamLabel> pageInfo, ExamLabel examLabel) {
        // 条件构造器
        QueryWrapper<ExamLabel> queryWrapper = new QueryWrapper<>();
        System.out.println(examLabel.toString());
        if(examLabel.getLabelname()!=null&&examLabel.getLabelname()!="") {
            // 模糊查询Like
            queryWrapper.like("name", examLabel.getLabelname());
        }

        // 分页插件
        Page<ExamLabel> page = new Page(pageInfo.getCurrent(), pageInfo.getSize());
        page = this.page(page, queryWrapper);
        return new PagerInfo<>(page.getTotal(), page.getRecords(),page.getPages(),page.getCurrent(),page.getSize());
    }

    @Override
    public Boolean deleteLabel(String id) {
        Boolean result = this.removeById(id);
        return result;
    }

    @Override
    public Boolean deleteBatch(List<String> ids) {
        Boolean result = this.removeByIds(ids);
        return result;
    }

    @Override
    public Boolean addLabel(ExamLabel ExamLabel) {
        Boolean result = this.save(ExamLabel);
        return result;
    }

    @Override
    public Boolean updateLabel(ExamLabel ExamLabel) {
        Boolean result = this.updateById(ExamLabel);
        return result;
    }

    @Override
    public ExamLabel getLabel(Integer id) {
        ExamLabel examLabel=this.getById(id);
        return examLabel;
    }
}
